package com.hanliy.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hanliy.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

/**
 * @author hanyulin
 * @apiNote
 * @date 2021/12/20 15:29
 */
@RestController
@Api(tags = "商品相关")
public class SortController {

    @Autowired
    private UserService userService;

    @GetMapping("/page")
    @ApiOperation(value = "分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sort", value = "排序字段", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "order", value = "升序: asc，降序: desc", required = false, dataType = "String", paramType = "query")
    })
    public Page page(@ApiIgnore @RequestParam Map<String, Object> params) {
        // 如果是升序，就重新设置为升序
        if("asc".equals(params.get("order"))) {
            params.replace("order","asc");
        }else{
            params.replace("order","desc");
        }
        return userService.page(new Page<>(1,10),params);
    }
}
